//package com.spzx.order.listener;
//
//import com.rabbitmq.client.Channel;
//import org.springframework.amqp.core.ExchangeTypes;
//import org.springframework.amqp.core.Message;
//import org.springframework.amqp.rabbit.annotation.Exchange;
//import org.springframework.amqp.rabbit.annotation.Queue;
//import org.springframework.amqp.rabbit.annotation.QueueBinding;
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
//import org.springframework.stereotype.Component;
//
//import java.io.IOException;
//
//@Component
//public class MqTestListener {
//
//    @RabbitListener(bindings = {
//            //spring amqp默认配置了 交换机队列消息的持久化
//            @QueueBinding(exchange = @Exchange(value = "spzx.exchange",type = ExchangeTypes.TOPIC ),
//                value = @Queue(value = "spzx.queue.test1") ,
//                key = {"test1.#"}
//            )
//    })
//    public void testListener1(String message , Message msg , Channel channel){
//
//        try {
//            System.out.println("接收到消息："+message);
//            //手动ack
//            channel.basicAck(msg.getMessageProperties().getDeliveryTag(),
//                    false);
//        } catch (Exception e) {
////            throw new RuntimeException(e);
//            try {
//                if(msg.getMessageProperties().isRedelivered()){
//                    //是消费异常重新归队后 再次消费进入异常  丢弃消息：变为死信
//                    channel.basicReject(msg.getMessageProperties().getDeliveryTag(),false);
//                }else{
//                    //第一次消费异常 让消息归队 尝试重新消费
//                    channel.basicNack(msg.getMessageProperties().getDeliveryTag(),false,true);
//                }
//            } catch (IOException ex) {
//                throw new RuntimeException(ex);
//            }
//        }
//
//    }
//}
